class Solution {
public:
    vector<int> lexicalOrder(int n) {
        vector<int> ret;
        int cur=1;
        ret.push_back(cur);
        for(int i=1;i<n;i++)
        {
            if(cur*10<=n)
            {
                cur=cur*10;
            }
            else{
                while(cur%10==9 || cur+1>n)
                {
                    cur/=10;
                }
                cur++;
            }
            ret.push_back(cur);
        }
        return ret;
    }
};
